/*
* created by Administrator on 2018/12/11
* 好的代码像粥一样,是得用时间和精力熬的。
*/
import qs from 'qs';
// import {router} from '../router';
const ENV = {
  testing: 'http://api.com',
  development: 'http://localhost:8080',
  production: 'http://api.hopu.com',
};
export default {
  baseConf: {
  baseUrl: ENV[process.env.NODE_ENV],
  timeout: 5000,
},
  addInterceptor: {
    request(instance) {
      instance.interceptors.request.use(request => {
        if (request.method === 'post'){
          request.data = qs.stringify(request.data);
        }
        return request;
      },error => Promise.reject(error));
    },
    response(instance) {
      instance.interceptors.response.use(response => {
        if (response.data.code === 10001) { //code=10001 证明没有权限
          router.replace('/login');
        }
        if (response.data.code !==1){
          return Promise.reject()
        }
      }, error => Promise.reject(error));
    },
  },
};

